---@diagnostic disable: lowercase-global, undefined-global, trailing-space

---@type api_particle
local Particle = require('core_webber_the_trainer/api/particle')

local genpoint_particle_webbert_staff_healfx = CreateCircleEmitter(2)

---@type data_particle[]
local data = {
    -- {
    --     prefab                 = 'dmg_display',
    --     is_mod_texture         = true,
    --     texture                = 'fx/dmg_num.tex',
    --     texture_num_col        = 10,
    --     texture_num_row        = 1,
    --     enable_envelope_colour = true,
    --     enable_envelope_scale  = true,
    --     envelope_colour        = {
    --         {{0, {1,1,1,.7}},{.7, {1,1,1,1}},{1, {1,1,1,0}}},
    --     },
    --     envelope_scale = {
    --         Particle:genLerpEnvelopeScale(.6,3,.1),
    --     },
    --     custom_every_particle_style = false,
    --     custom_every_particle_style_use_same_envelope = true,
    --     custom_every_particle_style_false = {
    --         rotationstatus        = true,
    --         maxnum                = 200,
    --         life                  = 2,
    --         blendmode             = BLENDMODE.Premultiplied,
    --         enable_ground_physics = false,
    --         sort_offset           = 0,
    --         sort_order            = 0,
    --         enablebloompass       = true,
    --         acceleration          = {0,0,0},
    --         dragcoefficient       = .03,
    --     },
    --     emitter_type = {
    --         type  = 'once',
    --     },
    --     emit_when_spawn = false,
    --     emit_fn = function (inst)
    --         Particle:emitParticle(inst,0,4,0,0,0,0,function ()
    --             local fixed_x,fixed_z = Tools:findPointInLineParallelCamera()
    --             local dist = Tools:calcDist(0,0,fixed_x,fixed_z,true)
    --             local px, pz = Tools:findPointOnLine(0,0, fixed_x, fixed_z, dist,i*0.5)
    --             local py = 2
    --             local vx, vy, vz = 0, 2, 0
    --             return px, py, pz, vx, vy, vz
    --         end)
    --     end
    -- },
    -- 治疗上升粒子
    {
        prefab = 'particle_webbert_staff_healfx',
        is_mod_texture = true,
        texture = 'fx/webbert_staff_healfx.tex',
        texture_num_col = 1,
        texture_num_row = 1,
        enable_envelope_colour = true,
        enable_envelope_scale = true,
        envelope_colour = {
            {{0, {1,1,1,0}},{.7, {1,1,1,.8}},{1, {1,1,1,0}}},
        },
        envelope_scale = {
            Particle:genLerpEnvelopeScale(.6,.1,.05)
        },
        custom_every_particle_style = false,
        custom_every_particle_style_use_same_envelope = true,
        custom_every_particle_style_false = {
            rotationstatus = true,
            maxnum = 200,
            life = 2.5,
            enablebloompass = true,
            sort_order = 0,
            sort_offset = 0,
            enable_ground_physics = false,
            acceleration = {0,0,0},
            dragcoefficient = .05,
            blendmode = BLENDMODE.Premultiplied,
        },
        emitter_type = {
            type = 'delay',
            delay = .5,
        },
        emit_when_spawn = true,
        emit_fn = function (inst)
            -- for i = 1, 1 do
                local num = 5
                repeat
                    num = num - 1
                    Particle:emitParticle(inst,0,nil,nil,nil,0,0,function ()
                        local px,pz = genpoint_particle_webbert_staff_healfx()
                        local py = math.random() * 2
                        local vx, vy, vz = 0, .08, 0
                        return px, py, pz, vx, vy, vz
                    end)
                until num < 0
            -- end
        end
    },
    -- 睡觉滋滋滋
    {
        prefab = 'particle_webbert_sleep_zzz',
        is_mod_texture = true,
        texture = 'fx/webbert_zzz.tex',
        -- texture = 'images/fx/webbert_zzz_bold.tex',
        texture_num_col = 1,
        texture_num_row = 1,
        enable_envelope_colour = true,
        enable_envelope_scale = true,
        envelope_colour = {
            {{0, {1,1,1,0}},{.7, {1,1,1,1}},{1, {1,1,1,0}}},
        },
        envelope_scale = {
            Particle:genLerpEnvelopeScale(.1,.4,.05)
        },
        custom_every_particle_style = false,
        custom_every_particle_style_use_same_envelope = true,
        custom_every_particle_style_false = {
            rotationstatus = true,
            maxnum = 50,
            life = 2,
            enablebloompass = false,
            sort_order = 0,
            sort_offset = 0,
            enable_ground_physics = false,
            acceleration = {0,0,0},
            dragcoefficient = .05,
            blendmode = BLENDMODE.Premultiplied,
        },
        emitter_type = {
            type = 'delay',
            delay = 0.2,
        },
        emit_when_spawn = true,
        emit_fn = function (inst)
            -- local num = 3
            -- repeat
            --     num = num - 1
                Particle:emitParticle(inst,0,1,nil,nil,0,0,function ()
                    local px,pz = 0,0
                    local py = .5
                    local vx, vy, vz = 0, .08, .06*UnitRand()
                    return px, py, pz, vx, vy, vz
                end)
            -- until num < 0
        end
    },
    -- 黑块往内吸收
    {
        prefab = 'particle_webbert_globalsquare',
        is_mod_texture = true,
        texture = 'fx/webbert_globalsquare.tex',
        texture_num_col = 1,
        texture_num_row = 1,
        enable_envelope_colour = true,
        enable_envelope_scale = true,
        envelope_colour = {
            {{0, {1,1,1,0}},{.7, {1,1,1,1}},{1, {1,1,1,0}}},
        },
        envelope_scale = {
            Particle:genLerpEnvelopeScale(1.2,.2,.05)
        },
        custom_every_particle_style = false,
        custom_every_particle_style_use_same_envelope = true,
        custom_every_particle_style_false = {
            rotationstatus = true,
            maxnum = 400,
            life = 2,
            enablebloompass = false,
            sort_order = 0,
            sort_offset = 0,
            enable_ground_physics = false,
            acceleration = {0,0,0},
            dragcoefficient = .05,
            blendmode = BLENDMODE.AlphaBlended,
        },
        emitter_type = {
            type = '鲵鱼',
        },
        emit_when_spawn = true,
        emit_fn = function (inst)
            local num = inst._num_to_emit or 2
            repeat
                num = num - 1
                Particle:emitParticle(inst,0,nil,nil,nil,0,0,function ()
                    local w = inst.particle_data and inst.particle_data[1] and inst.particle_data[1]*1 or nil
                    local px, py, pz = CreateSphereEmitter(w and w*.8 or 2.5)()
                    if inst._num_to_emit == nil then
                        ---@diagnostic disable-next-line: inject-field
                        inst._num_to_emit = w and ((w>5 and 8) or (w>3 and 4)) or 2
                    end
                    local vx, vy, vz = -px, -py, -pz
                    local speed = .14
                    local length = math.sqrt(vx^2 + vy^2 + vz^2)
                    if length > 0 then
                        vx = (vx / length) * speed
                        vy = (vy / length) * speed
                        vz = (vz / length) * speed
                    end
                    return px, py, pz, vx, vy, vz
                end)
            until num < 0
        end,
        hasnetvar = true,
    },
    -- 眩晕星星
    {
        prefab = 'particle_webbert_stun_star',
        is_mod_texture = true,
        texture = 'fx/webbert_star.tex',
        texture_num_col = 1,
        texture_num_row = 1,
        enable_envelope_colour = true,
        enable_envelope_scale = true,
        envelope_colour = {
            {{0, {1,1,1,0}},{.7, {1,1,1,1}},{1, {1,1,1,0}}},
        },
        envelope_scale = {
            Particle:genLerpEnvelopeScale(1.2,.2,.05)
        },
        custom_every_particle_style = false,
        custom_every_particle_style_use_same_envelope = true,
        custom_every_particle_style_false = {
            rotationstatus = true,
            maxnum = 200,
            life = 2,
            enablebloompass = false,
            sort_order = 0,
            sort_offset = 0,
            enable_ground_physics = false,
            acceleration = {0,0,0},
            dragcoefficient = .05,
            blendmode = BLENDMODE.Premultiplied,
        },
        emitter_type = {
            type = 'delay',
            delay = 0.2,
        },
        emit_when_spawn = true,
        emit_fn = function (inst)
            local num = 5
            repeat
                num = num - 1
                Particle:emitParticle(inst,0,nil,nil,nil,0,0,function ()
                    local px, pz = CreateRingEmitter((inst.particle_data and inst.particle_data[1] or 2)*.4)()
                    local vx, vy, vz = 0,0,0
                    local py = (inst.particle_data and inst.particle_data[2] or 2)*.8
                    return px, py, pz, vx, vy, vz
                end)
            until num < 0
        end,
        hasnetvar = true,
    },
    
}

return unpack(Particle:MakeParticles(data))